#include <stdio.h>
int val[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
int hashCheck[11]={1,0,10,9,8,7,6,5,4,3,2};
int main(){
    int T,check,checkVal;
    scanf("%d",&T);
    char tmp[20];
    for(int i=1;i<=T;i++){
        check = 0;
        scanf("%s",tmp);
        for(int j=0;j<17;j++){
            check+=(tmp[j]-'0')*val[j];
           // printf("%d ",(tmp[j]-'0')*val[j]);
        }
        if(tmp[17]=='X')checkVal=10;
        else checkVal=tmp[17]-'0';
        //printf("%d %d ",check,checkVal);
        if(check%11==hashCheck[checkVal])printf("right\n");
        else printf("wrong\n");
    }
    return 0;
}